package com.zw.pdm.module.est.controller;

import com.zw.pdm.base.BaseController;
import com.zw.pdm.common.JsonResult;
import com.zw.pdm.module.basic.service.DictCommonService;
import com.zw.pdm.module.est.service.CopyCardService;
import com.zw.pdm.module.report.model.Project;
import com.zw.pdm.module.report.service.SheetService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

/**
 * @Description: 复制工艺卡
 * @Author: China.wsg
 * @Date: 2021/6/18 16:11
 */
@Controller
@RequestMapping("/est/copy")
@SuppressWarnings("all")
public class CopyCardController extends BaseController {

    @Autowired
    private CopyCardService copyCardService;
    @Autowired
    private DictCommonService dictCommonService;
    @Autowired
    private SheetService sheetService;

    @GetMapping
    @RequiresPermissions({"est:copy:view"})
    public String page() {
        return "est/copy/page";
    }

    /**
     * @Author wsg
     * @Date 9:20 2021/6/19
     * @Description 根据项目编号查询项目列表
     **/
    @GetMapping("/projectList")
    @ResponseBody
    @RequiresPermissions({"est:copy:view"})
    public List<Project> projectList(String q) {
        return copyCardService.findProjectByCode(q);
    }

    /**
     * @Author wsg
     * @Date 9:20 2021/6/19
     * @Description 工艺卡复制
     **/
    @ResponseBody
    @PostMapping("/estCopy")
    @RequiresPermissions({"est:copy:edit"})
    public JsonResult estCopy(String proCodeS, String proCodeC) {
        Integer result = copyCardService.estCopy(proCodeS, proCodeC);
        if (result.compareTo(10) == 0) {
            return error("被复制的项目有未被审核的工艺卡，不允许复制");
        } else if (result.compareTo(20) == 0) {
            return error("被复制项目与复制项目的制作件清单不一致，不允许复制");
        } else if (result.compareTo(30) == 0) {
            return error("复制的项目已经创建过工艺卡，不允许复制");
        }
        return success();
    }


}
